import { computed, ref } from 'vue'
import { useStore } from 'vuex'
import get from 'lodash/get'
import { ObjectType } from 'typings/interfaces'

function useOrgTree() {
  const loading = ref<boolean>(false)
  const store = useStore()
  const orgTree = computed<Array<ObjectType>>(() => store.getters.orgTree)
  const organId = computed<string>(() => get(store.getters.orgTree, '0.children.0.children.0.id'))

  return {
    loading,
    orgTree,
    organId,
  }
}

export default useOrgTree
